package com.jk.mapper;

import com.jk.entity.Payment;
import com.jk.entity.TransferRecord;
import com.jk.entity.YuEBao;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by 动物的 on 2017/12/21.
 */
public interface YuebaoMapper {

     /**查询*/
    @Select("select yu.existingYue,yu.accumulatedIncome from yu_ebao yu where yu.userid = #{userId}")
     public YuEBao selectYuebao(String userId);

     /**转入（修改余额宝余额）[将账户余额转入余额宝余额  (余额宝 +)  ]*/
     @Update("update yu_ebao yu set yu.existingYue = yu.existingYue + #{shiftTo} where yu.userid = #{userId}")
     public void updYuebao(@Param("userId") String userId,@Param("shiftTo") double shiftTo);

    /**转入（修改账户余额） [将账户余额转入余额宝余额  (账户余额 -)  ]*/
    @Update("update payment_account pt set pt.accountBalance = pt.accountBalance - #{shiftTo} where pt.userid = #{userId}")
     public void udaZhyue(@Param("userId") String userId,@Param("shiftTo") double shiftTo);

    /**转出（修改余额宝余额）[将余额宝余额转出到账户余额  (余额宝 -)  ]*/
    @Update("update yu_ebao yu set yu.existingYue = yu.existingYue - #{rollOut} where yu.userid = #{userId}")
    void updYuebaoZhuanchu(@Param("userId") String userId,@Param("rollOut") double rollOut);

    /**转出（修改账户余额）[将余额宝余额转出到账户余额  (账户余额 +)  ]*/
    @Update("update payment_account pt set pt.accountBalance = pt.accountBalance + #{rollOut} where pt.userid = #{userId}")
    void udaZhyueZhuanchu(@Param("userId") String userId,@Param("rollOut") double rollOut);

    /**添加转账记录*/
    @Insert("insert into transfer_record values(#{id},#{recordName},#{dealMoney},#{dealStatus},#{dealDate},#{userId})")
    void addRecord(TransferRecord tr);




    /**查询交易记录*/
    @Select("select * from transfer_record t where t.userId = #{userId}")
    @Results({
            @Result(property ="id",column = "id"),
            @Result(property ="recordName",column = "recordName"),
            @Result(property ="dealMoney",column = "dealMoney"),
            @Result(property ="dealStatus",column = "dealStatus"),
            @Result(property ="dealDate",column = "dealDate"),
            @Result(property ="userId",column = "userId")
             })
    List<TransferRecord> getTransferRecord(String userId);
    /**
     * 查询余额数据
     * @param userId
     * @return
     */
    @Select("select pa.accountBalance from payment_account pa where pa.userId = #{userId}")
    Payment selectZhye(String userId);
}
